package com.amigo.online.consumer.merchant;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

@Configuration
public class ThreadPoolConfig {

	@Bean(value = "uploadThreadPool")
	public ExecutorService buildConsumerQueueThreadPool() {
		ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("upload-queue-thread-%d").build();
		ExecutorService pool = new ThreadPoolExecutor(4, 64, 0L, TimeUnit.MILLISECONDS,
				new ArrayBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

		return pool;
	}
}
